<?php 
if(KT!='KhiThe') exit;
class sliderProduct_controller extends sliderProduct_model{
	
	public function __construct(){
		
		global $lang;
		
		$lang['url_base'] = url_base;	
		$this->path_cur = dirname(__FILE__);	
		parent::__construct();
		parent::addObject('khithe_template');
		parent::addObject('khithe_request');
		parent::addObject('khithe_string');
		parent::addObject('khithe_images');
		
		$this->lang = $lang;
	}
	public function index()
	{
			$resultHtml ='';
			$strModule = parent::khithe_display_template(dirname(__FILE__).'/sliderProduct');
			$arrBlockHtml = $this->khithe_getBlockHtml($strModule);
			$arrRowTop = parent::get_productTop(mt_rand(1, 10),10);
			
			if($arrRowTop>0){
				foreach ( $arrRowTop as $row_Top )
				{
											
					if($row_Top["PriceSpecial"]>0){
						$specialPrice = ($row_Top["Price"]!=0?number_format($row_Top["Price"]/$this->lang["rate"],0,".",",").' '.$this->lang["rates"]:$this->lang["Call"]);
						$Price = number_format($row_Top["PriceSpecial"]/$this->lang["rate"],0,".",",").' '.$this->lang["rates"];
						$PriceVal = $row_Top["PriceSpecial"]/$this->lang["rate"];
					}else{
						$Price = ($row_Top["Price"]!=0?number_format($row_Top["Price"]/$this->lang["rate"],0,".",",").' '.$this->lang["rates"]:$this->lang["Call"]);
						$PriceVal = ($row_Top["Price"]!=0?$row_Top["Price"]/$this->lang["rate"]:0);
						$specialPrice = '';	
					}
					
					$fileImg = path_base.'/uploads/products/'.$row_Top['Picture'];			
					$fileThumbImg = path_base.'/uploads/products/cache/'.$row_Top['Picture'];
					if(!is_file($fileThumbImg) && is_file($fileImg))
					{
						$this->setIMG($fileImg);
						$this->resizeImage(200, 180, 'auto');
						$this->saveImage($fileThumbImg);
					}
					$ThumbImg = url_base.'uploads/products/cache/'.$row_Top['Picture'];
					if(!is_file($fileThumbImg)){
						$ThumbImg =url_base.'uploads/products/cache/logo.png';
					}
					
					$resultHtml .= $this->khithe_assign($arrBlockHtml['new'], array(
						'Title_full'=>$row_Top["Title"],
						'Title_short'=>$row_Top["Title"],
						'url_proNew'=>url_base.($this->seo_list_parent(categorys,NULL,$row_Top['CategoryID'])).$row_Top['SeoKey'].'.html',
						'ThumbImg'=>$ThumbImg,
						'Price'=>$Price,
						'price-primary-val'=>$PriceVal,
						'product-id'=>$row_Top["ID"],
						'specialPrice'=>$specialPrice,
						'url_cart'=>url_base.'shoppingcarts/add/'.$row_Top["ID"],
					));	
				}
				$resultHtml = $this->khithe_assignBlock($strModule, array('htmlnew'=>$resultHtml));
			}
			
			$strModule = $this->khithe_assign($resultHtml, $this->lang);
			
			
			return $strModule;
			
		
	}
	


}
?>